import time
import warnings
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service


class UseBrowser:

    driver=None
    def __init__(self,name='edge',path='../../../MicrosoftWebDriver.exe'):
        warnings.filterwarnings('ignore', category=ResourceWarning)
        try:
            if name=='edge':
                s = Service(path)
                self.option = webdriver.EdgeOptions()
                self.option.add_experimental_option("detach", True)
                self.driver = webdriver.Edge(options=self.option,service=s)
            elif name=='chrome':
                s = Service("chromedriver.exe")
                self.option = webdriver.ChromeOptions()
                self.option.add_experimental_option("detach", True)
                self.driver = webdriver.Chrome(options=self.option,service=s)
            elif name=='firefox':
                pass
            else:
                print('support: edge,chrome,firefox')
        except Exception as e:
            print(e)

        UseBrowser.driver = self.driver
        self.driver.implicitly_wait(5)
        self.driver.maximize_window()

    @classmethod
    def quit(cls):
        time.sleep(2)
        cls.driver.quit()
# if __name__=='__main__':
#     ub=UseBrowser('edge','../MicrosoftWebDriver.exe')
#     ub.quit()